package com.example.finalassignment.mapper;

import com.example.finalassignment.pojo.Technology;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
* @author guocheng
* @description 针对表【technology】的数据库操作Mapper
* @createDate 2024-05-27 23:02:33
* @Entity com.example.finalassignment.pojo.Technology
*/
public interface TechnologyMapper {

    int deleteByPrimaryKey(Long id);

    int insert(Technology record);

    int insertSelective(Technology record);

    Technology selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Technology record);

    int updateByPrimaryKey(Technology record);

    /**
     * 根据userid 查询所有数据
     */
    List<Map<String, Object>> getAllData(@Param("userId") String userId);

    /**
     * 分页查询
     */
    List<Map<String, Object>> getDataByLimit(@Param("userId") String userId, @Param("start") Integer start, @Param("pages") Integer pages);

    /**
     * 根据uuid查询文章
     */
    @Select("select a.*,b.description,b.show_photo,b.stars,b.watch,c.name " +
            "from technology as a left join technology_info as b " +
            "on a.uuid = b.uuid left join user as c on a.user_id = c.id " +
            "where a.uuid = #{uuid}")
    Map<String,Object> getDraftsByUUID(@Param("uuid") String uuid);

    @Update("update technology set status = 3 where uuid = #{uuid}")
    int deleteDraftsByUUID(@Param("uuid") String uuid);

    /**
     * 分页查询所有文章
     */
    @Select("select a.*,b.description,b.show_photo,b.stars,b.watch,c.name " +
            "from technology as a left join technology_info as b " +
            "on a.uuid = b.uuid left join user as c on a.user_id = c.id " +
            "where a.status = 1 order by a.create_time desc " +
            "limit #{start},#{pages}")
    List<Map<String, Object>> getAllDataByLimit(@Param("start") Integer start, @Param("pages") Integer pages);

    /**
     * 查询所有文章
     */
    @Select("select a.*,b.description,b.show_photo,b.stars,b.watch,c.name " +
            "from technology as a left join technology_info as b " +
            "on a.uuid = b.uuid left join user as c on a.user_id = c.id " +
            "where a.status = 1 order by a.create_time desc ")
    List<Map<String, Object>> getAllDataByNoLimit();

    /**
     * 分页模糊查询所有文章
     */
    @Select("select a.*,b.description,b.show_photo,b.stars,b.watch,c.name " +
            "from technology as a left join technology_info as b " +
            "on a.uuid = b.uuid left join user as c on a.user_id = c.id " +
            "where a.status = 1 and " +
            "(a.title like concat('%',#{value},'%') or a.content like concat('%',#{value},'%') or b.description like concat('%',#{value},'%'))" +
            "order by a.create_time desc " +
            "limit #{start},#{pages}")
    List<Map<String, Object>> getAllDataByLimitLike(@Param("value") String value,@Param("start") Integer start, @Param("pages") Integer pages);

    /**
     * 模糊查询所有文章
     */
    @Select("select a.*,b.description,b.show_photo,b.stars,b.watch,c.name " +
            "from technology as a left join technology_info as b " +
            "on a.uuid = b.uuid left join user as c on a.user_id = c.id " +
            "where a.status = 1 " +
            "and (a.title like concat('%',#{value},'%') or a.content like concat('%',#{value},'%') or b.description like concat('%',#{value},'%'))" +
            " order by a.create_time desc ")
    List<Map<String, Object>> getAllDataByNoLimitLike(@Param("value") String value);
}
